/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainJFrame.java
 *
 * Created on 04-Jul-2011, 12:14:00
 */
package picasaphotomanager.JFrames;

import autoUpdate.albumList.AlbumListUpdateEvent;
import autoUpdate.albumList.IAlbumListUpdateListener;
import com.google.gdata.data.photos.AlbumEntry;
import com.google.gdata.data.photos.PhotoEntry;
import com.google.gdata.util.ServiceException;
import configuration.ConfigurationManager;
import configuration.PicasaAccount;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import guiExtentions.WebAlbumRenderer;
import java.net.URL;
import java.text.SimpleDateFormat;
import picasaphotomanager.PicasaSessionManager;
import autoUpdate.WatchEntry;
import com.google.gdata.util.NotImplementedException;
import configuration.Preferences;
import guiExtentions.AlbumListModel;
import java.awt.AWTException;
import java.awt.Image;
import java.awt.SystemTray;
import java.awt.TrayIcon;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.text.DateFormat;
import java.util.ArrayList;
import javax.swing.DefaultListModel;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.filechooser.FileSystemView;
import picasaphotomanager.PicasaPhotoManager;
import picasaphotomanager.PicasaSession;
import platforms.PlatformSupport;
import platforms.PlatformSupport.PLATFORM;
import sync.merge.MediaContent;
import sync.merge.MergeManager;
import utilities.DataFormater;

/**
 *
 * @author zalem1
 */
    public class MainJFrame extends javax.swing.JFrame implements IAlbumListUpdateListener {
    private static JFrame _classInstance;

    private SystemTray _systemTray;
    private TrayIcon _systemTrayIcon;
    private String _formTitlePrefix;
    private MergeManager _manager = new MergeManager();
    private AlbumListModel _model = new AlbumListModel();

    /** Creates new form MainJFrame */
    public MainJFrame() {
        initComponents();
        _classInstance = this;
        
        SetupSysTrayIcon();
        _formTitlePrefix = getTitle();
        try {
            List<Image> icons = new ArrayList<Image>();
            
            for (String imageResolution : new String[] { "16", "32", "48", "64", "128" } ) {
                URL image = getClass().getResource("/resources/images/Synchronize-" + imageResolution + ".png");
                icons.add(ImageIO.read(image));
            }
            
            setIconImages(icons);
        } catch (IOException ex) {
            Logger.getLogger(MainJFrame.class.getName()).log(Level.SEVERE, "Couldn't set the form image", ex);
        }

        //Do not add menu in Mac
        if (PlatformSupport.getPlatformName() != PLATFORM.MAC)
            setMenuBar(mainMenuBar);
    }


    public static JFrame getInstance(JFrame parent) {
        return _classInstance;
    }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        sysTrayPopupMenu = new java.awt.PopupMenu();
        RestoreMenuItem = new java.awt.MenuItem();
        PreferencesMenuItem = new java.awt.MenuItem();
        CloseMenuItem = new java.awt.MenuItem();
        mainMenuBar = new java.awt.MenuBar();
        FileMenu = new java.awt.Menu();
        PreferencesMMenuItem = new java.awt.MenuItem();
        ExitMenuItem = new java.awt.MenuItem();
        AboutMenu = new java.awt.Menu();
        AboutMenuItem = new java.awt.MenuItem();
        jScrollPane1 = new javax.swing.JScrollPane();
        WebAlbumList = new javax.swing.JList();
        ConnectButton = new javax.swing.JButton();
        Panel = new javax.swing.JPanel();
        PhotosLabel = new javax.swing.JLabel();
        MoviesLabel = new javax.swing.JLabel();
        PhotosCountLabel = new javax.swing.JLabel();
        MoviesCountLabel = new javax.swing.JLabel();
        SizeLabel = new javax.swing.JLabel();
        AlbumSizeLabel = new javax.swing.JLabel();
        OwnerLabell = new javax.swing.JLabel();
        OwnerNameLabel = new javax.swing.JLabel();
        AlbumSettingsTabbedPane = new javax.swing.JTabbedPane();
        AlbumInformationPanel = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        TitleLabel = new javax.swing.JLabel();
        DescriptionLabel = new javax.swing.JLabel();
        VisibilityLabel = new javax.swing.JLabel();
        TitleTextField = new javax.swing.JTextField();
        DescriptionTextField = new javax.swing.JTextField();
        VisibilityPublicRadioButton = new javax.swing.JRadioButton();
        VisibilityPrivateRadioButton = new javax.swing.JRadioButton();
        DateLabel = new javax.swing.JLabel();
        DateFormattedTextField = new javax.swing.JFormattedTextField();
        LocationLabel = new javax.swing.JLabel();
        LocationTextField = new javax.swing.JTextField();
        VisibilitySharedRadioButton = new javax.swing.JRadioButton();
        jImage1 = new guiExtentions.JImage();
        AlbumSyncPanel = new javax.swing.JPanel();
        enableSyncToggleButton = new javax.swing.JToggleButton();
        localPathLabel = new javax.swing.JLabel();
        localPathTextField = new javax.swing.JTextField();
        browseButton = new javax.swing.JButton();
        oneOffDownloadCheckBox = new javax.swing.JCheckBox();
        SaveButton = new javax.swing.JButton();
        LastUpdatedLabel = new javax.swing.JLabel();
        LastUpdatedDateLabel = new javax.swing.JLabel();
        DefaultResolutionComboBox = new javax.swing.JComboBox();
        DefaultResolutionLabel = new javax.swing.JLabel();
        DisconnectButton = new javax.swing.JButton();
        RefreshButton = new javax.swing.JButton();

        sysTrayPopupMenu.setActionCommand("sysTrayPopupMenu");
        sysTrayPopupMenu.setLabel("Picasa Photo Manager");
        sysTrayPopupMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sysTrayPopupMenuActionPerformed(evt);
            }
        });

        RestoreMenuItem.setFont(new java.awt.Font("Dialog", 1, 12));
        RestoreMenuItem.setLabel("Restore");
        RestoreMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RestoreMenuItemActionPerformed(evt);
            }
        });
        sysTrayPopupMenu.add(RestoreMenuItem);
        sysTrayPopupMenu.addSeparator();
        PreferencesMenuItem.setLabel("Preferences...");
        PreferencesMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PreferencesMenuItemActionPerformed(evt);
            }
        });
        sysTrayPopupMenu.add(PreferencesMenuItem);

        CloseMenuItem.setLabel("Close");
        CloseMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CloseMenuItemActionPerformed(evt);
            }
        });
        sysTrayPopupMenu.add(CloseMenuItem);

        FileMenu.setLabel("File");

        PreferencesMMenuItem.setActionCommand("Preferences");
        PreferencesMMenuItem.setLabel("Preferences");
        PreferencesMMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PreferencesMMenuItemActionPerformed(evt);
            }
        });
        FileMenu.add(PreferencesMMenuItem);

        ExitMenuItem.setActionCommand("Exit");
        ExitMenuItem.setLabel("Exit");
        ExitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ExitMenuItemActionPerformed(evt);
            }
        });
        FileMenu.add(ExitMenuItem);

        mainMenuBar.add(FileMenu);

        AboutMenu.setActionCommand("About");
        AboutMenu.setLabel("About");

        AboutMenuItem.setActionCommand("About");
        AboutMenuItem.setLabel("About");
        AboutMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AboutMenuItemActionPerformed(evt);
            }
        });
        AboutMenu.add(AboutMenuItem);

        mainMenuBar.add(AboutMenu);

        setTitle("Picasa manager");
        setName("MainFrame"); // NOI18N
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        WebAlbumList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                WebAlbumListValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(WebAlbumList);

        ConnectButton.setText("Connect");
        ConnectButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ConnectButtonActionPerformed(evt);
            }
        });

        PhotosLabel.setFont(new java.awt.Font("Tahoma", 1, 10));
        PhotosLabel.setText("Photos:");
        PhotosLabel.setEnabled(false);

        MoviesLabel.setFont(new java.awt.Font("Tahoma", 1, 10));
        MoviesLabel.setText("Movies:");
        MoviesLabel.setEnabled(false);

        PhotosCountLabel.setFont(new java.awt.Font("Tahoma", 0, 10));
        PhotosCountLabel.setText("    ");
        PhotosCountLabel.setEnabled(false);
        PhotosCountLabel.setFocusable(false);

        MoviesCountLabel.setFont(new java.awt.Font("Tahoma", 0, 10));
        MoviesCountLabel.setText("    ");
        MoviesCountLabel.setEnabled(false);
        MoviesCountLabel.setFocusable(false);

        SizeLabel.setFont(new java.awt.Font("Tahoma", 1, 10));
        SizeLabel.setText("Size:");
        SizeLabel.setEnabled(false);

        AlbumSizeLabel.setFont(new java.awt.Font("Tahoma", 0, 10));
        AlbumSizeLabel.setText("    ");
        AlbumSizeLabel.setEnabled(false);
        AlbumSizeLabel.setFocusable(false);

        OwnerLabell.setFont(new java.awt.Font("Tahoma", 1, 10));
        OwnerLabell.setText("Owner:");
        OwnerLabell.setEnabled(false);

        OwnerNameLabel.setFont(new java.awt.Font("Tahoma", 0, 10));
        OwnerNameLabel.setText("    ");
        OwnerNameLabel.setEnabled(false);
        OwnerNameLabel.setFocusable(false);

        javax.swing.GroupLayout PanelLayout = new javax.swing.GroupLayout(Panel);
        Panel.setLayout(PanelLayout);
        PanelLayout.setHorizontalGroup(
            PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(OwnerLabell)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(OwnerNameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(PhotosLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(PhotosCountLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(MoviesLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(MoviesCountLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(SizeLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(AlbumSizeLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(116, Short.MAX_VALUE))
        );
        PanelLayout.setVerticalGroup(
            PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, PanelLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(OwnerLabell)
                    .addComponent(PhotosLabel)
                    .addComponent(OwnerNameLabel)
                    .addComponent(PhotosCountLabel)
                    .addComponent(MoviesLabel)
                    .addComponent(MoviesCountLabel)
                    .addComponent(SizeLabel)
                    .addComponent(AlbumSizeLabel))
                .addContainerGap())
        );

        TitleLabel.setFont(new java.awt.Font("Tahoma", 1, 11));
        TitleLabel.setText("Title:");

        DescriptionLabel.setFont(new java.awt.Font("Tahoma", 1, 11));
        DescriptionLabel.setText("Description:");

        VisibilityLabel.setFont(new java.awt.Font("Tahoma", 1, 11));
        VisibilityLabel.setText("Visibility:");

        TitleTextField.setEnabled(false);

        DescriptionTextField.setEnabled(false);
        DescriptionTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DescriptionTextFieldActionPerformed(evt);
            }
        });

        VisibilityPublicRadioButton.setText("Public");
        VisibilityPublicRadioButton.setEnabled(false);

        VisibilityPrivateRadioButton.setText("Private");
        VisibilityPrivateRadioButton.setEnabled(false);

        DateLabel.setFont(new java.awt.Font("Tahoma", 1, 11));
        DateLabel.setText("Date taken:");

        DateFormattedTextField.setEnabled(false);

        LocationLabel.setFont(new java.awt.Font("Tahoma", 1, 11));
        LocationLabel.setText("Location:");

        LocationTextField.setEnabled(false);

        VisibilitySharedRadioButton.setText("Shared");
        VisibilitySharedRadioButton.setEnabled(false);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(LocationLabel)
                            .addComponent(DateLabel)
                            .addComponent(TitleLabel))
                        .addGap(5, 5, 5)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(DateFormattedTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 495, Short.MAX_VALUE)
                            .addComponent(LocationTextField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 495, Short.MAX_VALUE)
                            .addComponent(TitleTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 495, Short.MAX_VALUE)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(DescriptionLabel)
                            .addComponent(VisibilityLabel))
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(32, 32, 32)
                                .addComponent(VisibilityPublicRadioButton, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(VisibilitySharedRadioButton, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(VisibilityPrivateRadioButton, javax.swing.GroupLayout.DEFAULT_SIZE, 261, Short.MAX_VALUE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(4, 4, 4)
                                .addComponent(DescriptionTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 495, Short.MAX_VALUE)))))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TitleLabel)
                    .addComponent(TitleTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(DateLabel)
                    .addComponent(DateFormattedTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(LocationLabel)
                    .addComponent(LocationTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(DescriptionLabel)
                    .addComponent(DescriptionTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(VisibilityPublicRadioButton)
                    .addComponent(VisibilitySharedRadioButton)
                    .addComponent(VisibilityPrivateRadioButton)
                    .addComponent(VisibilityLabel))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jImage1Layout = new javax.swing.GroupLayout(jImage1);
        jImage1.setLayout(jImage1Layout);
        jImage1Layout.setHorizontalGroup(
            jImage1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 586, Short.MAX_VALUE)
        );
        jImage1Layout.setVerticalGroup(
            jImage1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 258, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout AlbumInformationPanelLayout = new javax.swing.GroupLayout(AlbumInformationPanel);
        AlbumInformationPanel.setLayout(AlbumInformationPanelLayout);
        AlbumInformationPanelLayout.setHorizontalGroup(
            AlbumInformationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(AlbumInformationPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(AlbumInformationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jImage1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        AlbumInformationPanelLayout.setVerticalGroup(
            AlbumInformationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(AlbumInformationPanelLayout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jImage1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        AlbumSettingsTabbedPane.addTab("Web Album", AlbumInformationPanel);

        AlbumSyncPanel.setEnabled(false);

        enableSyncToggleButton.setText("Enable Synch");

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, AlbumSyncPanel, org.jdesktop.beansbinding.ELProperty.create("${enabled}"), enableSyncToggleButton, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        enableSyncToggleButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                enableSyncToggleButtonActionPerformed(evt);
            }
        });

        localPathLabel.setText("Local Path:");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, enableSyncToggleButton, org.jdesktop.beansbinding.ELProperty.create("${selected&&enabled}"), localPathLabel, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, enableSyncToggleButton, org.jdesktop.beansbinding.ELProperty.create("${selected&&enabled}"), localPathTextField, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        browseButton.setText("...");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, enableSyncToggleButton, org.jdesktop.beansbinding.ELProperty.create("${selected&&enabled}"), browseButton, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        browseButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                browseButtonActionPerformed(evt);
            }
        });

        oneOffDownloadCheckBox.setText("Download only once");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, enableSyncToggleButton, org.jdesktop.beansbinding.ELProperty.create("${selected&&enabled}"), oneOffDownloadCheckBox, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        SaveButton.setText("Save");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, enableSyncToggleButton, org.jdesktop.beansbinding.ELProperty.create("${selected&&enabled}"), SaveButton, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        SaveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SaveButtonActionPerformed(evt);
            }
        });

        LastUpdatedLabel.setFont(new java.awt.Font("Tahoma", 1, 10));
        LastUpdatedLabel.setText("Last updated:");
        LastUpdatedLabel.setEnabled(false);

        LastUpdatedDateLabel.setFont(new java.awt.Font("Tahoma", 0, 10));
        LastUpdatedDateLabel.setText("    ");
        LastUpdatedDateLabel.setEnabled(false);
        LastUpdatedDateLabel.setFocusable(false);

        DefaultResolutionComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Original resolution", "Large", "Medium", "Small" }));

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, enableSyncToggleButton, org.jdesktop.beansbinding.ELProperty.create("${selected&&enabled}"), DefaultResolutionComboBox, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        DefaultResolutionLabel.setText("Default photo resolution:");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, enableSyncToggleButton, org.jdesktop.beansbinding.ELProperty.create("${selected&&enabled}"), DefaultResolutionLabel, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        javax.swing.GroupLayout AlbumSyncPanelLayout = new javax.swing.GroupLayout(AlbumSyncPanel);
        AlbumSyncPanel.setLayout(AlbumSyncPanelLayout);
        AlbumSyncPanelLayout.setHorizontalGroup(
            AlbumSyncPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(AlbumSyncPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(AlbumSyncPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(oneOffDownloadCheckBox)
                    .addComponent(enableSyncToggleButton)
                    .addGroup(AlbumSyncPanelLayout.createSequentialGroup()
                        .addComponent(LastUpdatedLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(LastUpdatedDateLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 351, Short.MAX_VALUE)
                        .addComponent(SaveButton))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, AlbumSyncPanelLayout.createSequentialGroup()
                        .addGroup(AlbumSyncPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, AlbumSyncPanelLayout.createSequentialGroup()
                                .addComponent(DefaultResolutionLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(DefaultResolutionComboBox, 0, 431, Short.MAX_VALUE))
                            .addGroup(AlbumSyncPanelLayout.createSequentialGroup()
                                .addComponent(localPathLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(localPathTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 498, Short.MAX_VALUE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(browseButton, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        AlbumSyncPanelLayout.setVerticalGroup(
            AlbumSyncPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(AlbumSyncPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(enableSyncToggleButton)
                .addGap(18, 18, 18)
                .addGroup(AlbumSyncPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(localPathLabel)
                    .addComponent(localPathTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(browseButton, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(AlbumSyncPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(DefaultResolutionLabel)
                    .addComponent(DefaultResolutionComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(oneOffDownloadCheckBox)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 277, Short.MAX_VALUE)
                .addGroup(AlbumSyncPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(AlbumSyncPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(LastUpdatedLabel)
                        .addComponent(LastUpdatedDateLabel))
                    .addComponent(SaveButton))
                .addContainerGap())
        );

        AlbumSettingsTabbedPane.addTab("Sync", AlbumSyncPanel);

        DisconnectButton.setText("Disconnect");
        DisconnectButton.setEnabled(false);
        DisconnectButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DisconnectButtonActionPerformed(evt);
            }
        });

        RefreshButton.setText("R");
        RefreshButton.setToolTipText("Refresh now!");
        RefreshButton.setMargin(new java.awt.Insets(2, 1, 2, 1));
        RefreshButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RefreshButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 295, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(ConnectButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(DisconnectButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(RefreshButton, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(AlbumSettingsTabbedPane, javax.swing.GroupLayout.DEFAULT_SIZE, 611, Short.MAX_VALUE)
                        .addContainerGap())
                    .addComponent(Panel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(AlbumSettingsTabbedPane, javax.swing.GroupLayout.DEFAULT_SIZE, 484, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 484, Short.MAX_VALUE))
                .addGap(12, 12, 12)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(ConnectButton)
                        .addComponent(DisconnectButton)
                        .addComponent(RefreshButton))
                    .addComponent(Panel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing

    }//GEN-LAST:event_formWindowClosing

    private void ConnectButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ConnectButtonActionPerformed
        Preferences configuration = ConfigurationManager.GetPreferences();

        //If there are no account show preferences screen
        if (configuration.getUserAccounts().isEmpty())
            PreferencesJFrame.getInstance(this).setVisible(true);

        //second attempt
        if (configuration.getUserAccounts().isEmpty()) return;
        
        for (PicasaAccount account : configuration.getUserAccounts())
            PicasaSessionManager.AddClient(account);
        
        _manager.start();
        WebAlbumList.setModel(_model);
        
        ConnectButton.setEnabled(false);
        DisconnectButton.setEnabled(true);        
    }//GEN-LAST:event_ConnectButtonActionPerformed

    private void WebAlbumListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_WebAlbumListValueChanged
        if (evt.getValueIsAdjusting()) return;
        
        MediaContent album = getSelectedAlbum();
        
        if (album == null) return;

        //Set the form title
        setTitle(_formTitlePrefix + " - " + album.getTitle() + " - " + album.getPicasaUsername());
        
        TitleTextField.setText(album.getTitle());
        DescriptionTextField.setText(album.getTitle());
        LocationTextField.setText(album.getLocation());

        SimpleDateFormat dateFormater = new SimpleDateFormat("dd MMMM yyyy");
        DateFormattedTextField.setText(dateFormater.format(album.getDate()));

        String accessType = album.getAccess().toLowerCase();
        if (accessType.equals("public"))
            VisibilityPublicRadioButton.setSelected(true);
        else if (accessType.equals("private"))
            VisibilityPrivateRadioButton.setSelected(true);
        else if (accessType.equals("shared"))
            VisibilitySharedRadioButton.setSelected(true);

        String albumSize = DataFormater.GetHumanReadableFileSize(album.getBytesUsed());

        PhotosCountLabel.setText(album.getPhotosUsed().toString());
        MoviesCountLabel.setText(album.getPhotosUsed().toString());
        AlbumSizeLabel.setText(albumSize);
        OwnerNameLabel.setText(album.getPicasaUsername());


        PicasaSession session = PicasaSessionManager.getSession(album.getPicasaUsername());
        List<PhotoEntry> photos = null;
        try {
            photos = session.PicasaClient.getPhotos(album, "72u", "-1");
        } catch (IOException ex) {
            Logger.getLogger(MainJFrame.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ServiceException ex) {
            Logger.getLogger(MainJFrame.class.getName()).log(Level.SEVERE, null, ex);
        }

        //remove old thumbnails
        jImage1.clearImages();
        
        try {
            int previewImageCount = ConfigurationManager.GetPreferences().getPreviewPictureCount();

            //limit number or preview pictures to the size of the photos
            previewImageCount = previewImageCount < photos.size() ? previewImageCount : photos.size();

            for (int imageIndex = 0; imageIndex < previewImageCount; imageIndex++) {
                PhotoEntry photo = photos.get(imageIndex);
                URL url = new URL(photo.getMediaThumbnails().get(0).getUrl());
                BufferedImage srcImage = ImageIO.read(url);
                jImage1.setImage(srcImage, imageIndex);
            }

            jImage1.repaint();

        } catch (IOException ex) {
            Logger.getLogger(MainJFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        //If the folder is watched use the saved local path
        String localPath = null;
        WatchEntry watchedAlbum = _manager.getWatchEntry(album.getId());
        if (watchedAlbum != null){
            localPath = watchedAlbum.getLocalPath();
            oneOffDownloadCheckBox.setSelected(watchedAlbum.isDownloadOnce());

            String lastOnlineUpdate = (new SimpleDateFormat("dd MMMM yyyy (hh:mm)")).format(watchedAlbum.getLastUpdatedLocally());
            LastUpdatedDateLabel.setText(lastOnlineUpdate);
        }
        //If that is a new folder construct new local path
        else if (localPath == null || localPath.isEmpty()) {
            String photoFolder = ConfigurationManager.GetPreferences().getDefaultPhotoFolder();
            String albumName = album.getTitle();
            localPath = (new File(photoFolder, albumName)).getPath();
            oneOffDownloadCheckBox.setSelected(false);
            LastUpdatedDateLabel.setText("Never");
        }

        localPathTextField.setText(localPath);
        DefaultResolutionComboBox.setSelectedIndex(PreferencesJFrame.getResolutionFromConfig(watchedAlbum.getPhotoResolution()));
        enableSyncToggleButton.setSelected(_manager.IsWatched(album.getId()));
        
        MediaContent selectedAlbum = getSelectedAlbum();
        AlbumSyncPanel.setEnabled(selectedAlbum != null);
    }//GEN-LAST:event_WebAlbumListValueChanged

    private void DescriptionTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DescriptionTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_DescriptionTextFieldActionPerformed

    private void enableSyncToggleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_enableSyncToggleButtonActionPerformed
        if (!enableSyncToggleButton.isSelected()) {
            MediaContent selectedAlbum = getSelectedAlbum();
            if (selectedAlbum != null)
                _manager.UnwatchAlbum(selectedAlbum.getLocalPath());
        }
        
    }//GEN-LAST:event_enableSyncToggleButtonActionPerformed

    private void DisconnectButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DisconnectButtonActionPerformed
        _manager.stop();

        ConnectButton.setEnabled(true);
        DisconnectButton.setEnabled(false);        
    }//GEN-LAST:event_DisconnectButtonActionPerformed

    private void sysTrayPopupMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sysTrayPopupMenuActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_sysTrayPopupMenuActionPerformed

    private void RestoreMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RestoreMenuItemActionPerformed
        setVisible(true);
    }//GEN-LAST:event_RestoreMenuItemActionPerformed

    private void CloseMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CloseMenuItemActionPerformed
        dispose();
    }//GEN-LAST:event_CloseMenuItemActionPerformed

    private void PreferencesMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PreferencesMenuItemActionPerformed
        PreferencesJFrame.getInstance(this).setVisible(true);
    }//GEN-LAST:event_PreferencesMenuItemActionPerformed

    private void PreferencesMMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PreferencesMMenuItemActionPerformed
        PreferencesJFrame.getInstance(this).setVisible(true);
    }//GEN-LAST:event_PreferencesMMenuItemActionPerformed

    private void ExitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ExitMenuItemActionPerformed
        setVisible(false);
    }//GEN-LAST:event_ExitMenuItemActionPerformed

    private void AboutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AboutMenuItemActionPerformed
        AboutJFrame.getInstance(this).setVisible(rootPaneCheckingEnabled);
    }//GEN-LAST:event_AboutMenuItemActionPerformed

    private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
        JFileChooser fileChooser = new JFileChooser(FileSystemView.getFileSystemView());
        fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        fileChooser.setSelectedFile(new File(localPathTextField.getText()));
        MediaContent selectedAlbum = getSelectedAlbum();
        
        if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            localPathTextField.setText(new File(fileChooser.getSelectedFile().getPath(), selectedAlbum.getTitle().getPlainText()).getPath());
        }
    }//GEN-LAST:event_browseButtonActionPerformed

    private void SaveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveButtonActionPerformed
        MediaContent album = getSelectedAlbum();
        album.setPhotoResolution(_formTitlePrefix);
        
        String mediaResolution = PreferencesJFrame.getResolutionFromDropdown(DefaultResolutionComboBox.getSelectedIndex());
        boolean downloadOnce = oneOffDownloadCheckBox.isSelected();
        
        album.setDownloadOnce(downloadOnce);
        album.setPhotoResolution(mediaResolution);
            
        //Update local path
        String newLocalPath = localPathTextField.getText();
        if (!newLocalPath.equals(album.getLocalPath()))
        {
            _manager.changeLocalPath(album.getLocalPath(), newLocalPath);
        }
        
    }//GEN-LAST:event_SaveButtonActionPerformed

    private void RefreshButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RefreshButtonActionPerformed
        _manager.refresh();
    }//GEN-LAST:event_RefreshButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new MainJFrame().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private java.awt.Menu AboutMenu;
    private java.awt.MenuItem AboutMenuItem;
    private javax.swing.JPanel AlbumInformationPanel;
    private javax.swing.JTabbedPane AlbumSettingsTabbedPane;
    private javax.swing.JLabel AlbumSizeLabel;
    private javax.swing.JPanel AlbumSyncPanel;
    private java.awt.MenuItem CloseMenuItem;
    private javax.swing.JButton ConnectButton;
    private javax.swing.JFormattedTextField DateFormattedTextField;
    private javax.swing.JLabel DateLabel;
    private javax.swing.JComboBox DefaultResolutionComboBox;
    private javax.swing.JLabel DefaultResolutionLabel;
    private javax.swing.JLabel DescriptionLabel;
    private javax.swing.JTextField DescriptionTextField;
    private javax.swing.JButton DisconnectButton;
    private java.awt.MenuItem ExitMenuItem;
    private java.awt.Menu FileMenu;
    private javax.swing.JLabel LastUpdatedDateLabel;
    private javax.swing.JLabel LastUpdatedLabel;
    private javax.swing.JLabel LocationLabel;
    private javax.swing.JTextField LocationTextField;
    private javax.swing.JLabel MoviesCountLabel;
    private javax.swing.JLabel MoviesLabel;
    private javax.swing.JLabel OwnerLabell;
    private javax.swing.JLabel OwnerNameLabel;
    private javax.swing.JPanel Panel;
    private javax.swing.JLabel PhotosCountLabel;
    private javax.swing.JLabel PhotosLabel;
    private java.awt.MenuItem PreferencesMMenuItem;
    private java.awt.MenuItem PreferencesMenuItem;
    private javax.swing.JButton RefreshButton;
    private java.awt.MenuItem RestoreMenuItem;
    private javax.swing.JButton SaveButton;
    private javax.swing.JLabel SizeLabel;
    private javax.swing.JLabel TitleLabel;
    private javax.swing.JTextField TitleTextField;
    private javax.swing.JLabel VisibilityLabel;
    private javax.swing.JRadioButton VisibilityPrivateRadioButton;
    private javax.swing.JRadioButton VisibilityPublicRadioButton;
    private javax.swing.JRadioButton VisibilitySharedRadioButton;
    private javax.swing.JList WebAlbumList;
    private javax.swing.JButton browseButton;
    private javax.swing.JToggleButton enableSyncToggleButton;
    private guiExtentions.JImage jImage1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel localPathLabel;
    private javax.swing.JTextField localPathTextField;
    private java.awt.MenuBar mainMenuBar;
    private javax.swing.JCheckBox oneOffDownloadCheckBox;
    private java.awt.PopupMenu sysTrayPopupMenu;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

    private MediaContent getSelectedAlbum() {
        MediaContent _selectedAlbum = null;
        // Get all selected items
        Object selected = WebAlbumList.getSelectedValue();

        if (selected != null && (selected instanceof MediaContent))
            _selectedAlbum = (MediaContent)selected;;

        return _selectedAlbum;
    }

    private void UpdateAlbumListModel(DefaultListModel model)
    {
        WebAlbumList.setModel(model);
        WebAlbumList.setCellRenderer(new WebAlbumRenderer());
    }

    @Override
    public void AlbumListUpdate(AlbumListUpdateEvent e) {
        try {
            //ToDo: Implement
            throw new NotImplementedException("Not implemented yet.");
        } catch (NotImplementedException ex) {
            Logger.getLogger(MainJFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void SetupSysTrayIcon() {        
        if (!SystemTray.isSupported()) {
            Logger.getLogger(PicasaPhotoManager.class.getName()).log(Level.WARNING, "System Tray is not supported in your Operating System.");
        }
        else {
            _systemTray = SystemTray.getSystemTray();
            InputStream sysTrayInputStream = null;            
            String sysTrayIconFilePath = ConfigurationManager.GetPreferences().getSystemTryIconPath();
            
            BufferedImage sysTrayIconImage = null;
            try {
                //Attempt to load custom icon
                if (sysTrayIconFilePath != null)
                   sysTrayInputStream = new FileInputStream(sysTrayIconFilePath);
                else //if that fails load the default
                   sysTrayInputStream = getClass().getResourceAsStream("/resources/images/Synchronize-16.png");
                        
                sysTrayIconImage = ImageIO.read(sysTrayInputStream);
                _systemTrayIcon = new TrayIcon(sysTrayIconImage, "Picasa Photo Manager");
                _systemTrayIcon.setImageAutoSize(true);
                _systemTrayIcon.setPopupMenu(sysTrayPopupMenu);
            
                _systemTray.add(_systemTrayIcon);

            } catch (AWTException ex) {
                Logger.getLogger(PicasaPhotoManager.class.getName()).log(Level.SEVERE, "Cannot add icon to the System Tray", ex);
            } catch (IOException ex) {
                Logger.getLogger(PicasaPhotoManager.class.getName()).log(Level.SEVERE, "Cannot read icon file from " + sysTrayIconFilePath , ex);
            }
        }
        
    }
         
    @Override
    public void dispose() {
        _manager.stop();
        ConfigurationManager.SaveConfiguration();

        super.dispose();
        
        _systemTray.remove(_systemTrayIcon);
    }
}
